package com.aspose.cells;

import java.util.ArrayList;

class zbwc {
   private Worksheet h;
   private Cells i;
   private zbwd j;
   private boolean k;
   private zgz l;
   private com.aspose.cells.b.a.d.zh m;
   private String n;
   int a = 0;
   int b = 0;
   int c = 0;
   int d = 0;
   zakl e = new zakl();
   zatq f;
   int g;

   zbwc(zbwd var1, int var2) throws Exception {
      this.j = var1;
      this.h = var1.a.e.getWorksheets().get(var2);
      this.i = this.h.getCells();
      this.k = false;
      int var3 = -1;
      if (var1.b != null) {
         zafw var4 = var1.b.a(this.h);
         if (var4 != null) {
            this.k = true;
            this.l = (zgz)var4;
            if (var1.c != null) {
               this.n = var1.c + "_Cells" + var2 + ".dat";
               com.aspose.cells.b.a.d.ze var5 = com.aspose.cells.b.a.d.zd.a(this.n);
               zqa var6 = new zqa(var5);
               this.a(var6, var4);
               var3 = (int)var5.h();
               var5.a();
            } else {
               this.m = new com.aspose.cells.b.a.d.zh(1024000);
               zqa var10 = new zqa(this.m);
               this.a(var10, var4);
               var3 = (int)this.m.h();
               if ((this.m.n() - var3) * 10 > var3) {
                  byte[] var12 = new byte[var3];
                  System.arraycopy(this.m.m(), 0, var12, 0, (int)this.m.h());
                  this.m = new com.aspose.cells.b.a.d.zh(var12, 0, var12.length, false, true);
               }
            }
         }
      }

      this.g = var3;
      if (!this.k) {
         zr var9 = this.i.f();
         if (var9.a() > 0) {
            int var11 = var9.b(65535);
            if (var11 < 0) {
               var11 = var9.a(-var11 - 1, true);
            }

            if (var11 > -1) {
               int var13 = var9.a(var11);
               int var7 = var9.c(0);
               if (var7 < var11) {
                  var7 = var9.a(var7);

                  for(int var8 = var13 / 32 - var7 / 32; var8 > -1; --var8) {
                     this.e.a(0);
                  }
               } else {
                  this.e.a(0);
               }
            }
         }
      }

   }

   void a(zqa var1) throws Exception {
      if (this.k) {
         if (this.n != null) {
            com.aspose.cells.b.a.d.ze var2 = com.aspose.cells.b.a.d.zd.b(this.n);
            zbom.a((com.aspose.cells.b.a.d.zm)var2, (com.aspose.cells.b.a.d.zm)var1.a());
            var2.a();
            com.aspose.cells.b.a.d.zd.d(this.n);
         } else if (this.m != null) {
            this.m.a(0L, 0);
            this.m.a(var1.a());
         }

      } else {
         this.a(var1, new zha(this.h));
      }
   }

   private void a(zqa var1, zafw var2) throws Exception {
      this.e.c();
      this.b = 0;
      this.d = 0;
      zp var3 = var2.c();
      if (var3 == null) {
         this.a = 0;
         this.c = 0;
      } else {
         com.aspose.cells.b.a.d.zh var4 = new com.aspose.cells.b.a.d.zh(128000);
         zqa var5 = new zqa(var4);
         com.aspose.cells.b.a.d.zh var6 = new com.aspose.cells.b.a.d.zh(640);
         zqa var7 = new zqa(var6);
         int var8 = (int)var1.b();
         this.a = -1;
         this.c = -1;
         int var9 = var3.h();
         int var10 = var9 - var9 % 32 + 31;
         boolean var11 = true;
         boolean var12 = false;
         boolean var13 = false;
         zbbj var17 = new zbbj();
         zakl var20 = new zakl();
         zakl var21 = new zakl();
         new ArrayList();
         ArrayList var23 = new ArrayList();

         do {
            this.h.getWorkbook().l();
            zbbj var18 = var3.a(var17, 15);
            boolean var16;
            int var19;
            if (var18.d()) {
               var19 = var3.i();
               var16 = var19 != 15;
            } else {
               var19 = 15;
               var16 = false;
            }

            if (this.k && this.l.a() == null && var16) {
               var19 = this.j.b.b(var19);
            }

            if (var19 >= 4095) {
               var19 = 15;
            }

            for(var9 = var18.a; var9 > var10; var10 += 32) {
               this.a(var23, var4, var6, var1, var8);
            }

            if (var9 > 65535) {
               break;
            }

            short var29 = 0;
            int var30 = 0;
            zfv var14 = var2.d();
            if (var14 != null) {
               var29 = var14.a;
               if (var29 < this.c || this.c < 0) {
                  this.c = var29;
               }

               do {
                  this.h.getWorkbook().l();
                  short var28 = var14.a;
                  if (var28 > 255) {
                     break;
                  }

                  if (var28 > var30 && var20.a() > 0) {
                     this.a(var5, var20, var21, var9, var30);
                  }

                  int var25;
                  if (var20.a() > 0) {
                     if (var14.c != 6) {
                        this.a(var5, var20, var21, var9, var30);
                     }
                  } else if (var21.a() > 0) {
                     if (var14.c != 0) {
                        this.a(var5, var21, var9, var30);
                     } else if (var28 - var30 > 3) {
                        this.a(var5, var21, var9, var30);
                     } else if (var30 < var28) {
                        for(int var24 = var30; var24 < var28; ++var24) {
                           if (var19 != 15) {
                              var21.a(var19);
                           } else {
                              var25 = this.i.d.a(var24);
                              var21.a(var25 < 0 ? 15 : var25);
                           }
                        }
                     }
                  }

                  int var15 = var14.b;
                  if (var15 == -1) {
                     if (var16) {
                        var15 = var19;
                     } else {
                        var15 = this.i.d.a(var28);
                        if (var15 < 0) {
                           var15 = 15;
                        }
                     }
                  } else if (this.k && var15 > 15 && this.l.b() == null) {
                     var15 = this.j.b.b(var15);
                  }

                  if (var15 >= 4095) {
                     var15 = 15;
                  }

                  switch(var14.c) {
                  case 0:
                     var21.a(var15);
                     break;
                  case 1:
                     var5.a((short)515);
                     var5.a((short)14);
                     var5.b(var9);
                     var5.a((short)var28);
                     var5.a((short)var15);
                     var5.a(com.aspose.cells.b.a.zc.a((Double)var14.d));
                     break;
                  case 2:
                     var5.a((short)517);
                     var5.a((short)8);
                     var5.b(var9);
                     var5.a((short)var28);
                     var5.a((short)var15);
                     var5.a((byte)((Boolean)var14.d ? 1 : 0));
                     var5.a((byte)0);
                     break;
                  case 3:
                     var5.a((short)517);
                     var5.a((short)8);
                     var5.b(var9);
                     var5.a((short)var28);
                     var5.a((short)var15);
                     var5.a((Byte)var14.d);
                     var5.a((byte)1);
                     break;
                  case 4:
                     var5.a((short)253);
                     var5.a((short)10);
                     var5.b(var9);
                     var5.a((short)var28);
                     var5.a((short)var15);
                     zayy var32 = (zayy)var14.d;
                     var25 = var32.e;
                     if (var25 < 0 || this.k && var25 >= this.j.b.d) {
                        var25 = 0;
                        if (this.k) {
                           var25 = this.j.b.a(var32.c);
                        }
                     } else {
                        if (var14.e && var32.g()) {
                           zatv var39 = (zatv)var14.d;
                           if (this.f == null) {
                              this.f = new zatq();
                              this.f.b = var39.b();
                              this.f.a = var39.c();
                           }

                           if (this.f.c.size() < 8192) {
                              CellArea var27 = new CellArea();
                              var27.StartRow = var27.EndRow = var9;
                              var27.EndColumn = var27.StartColumn = var14.a;
                              com.aspose.cells.b.a.a.ze.a(this.f.c, (Object)var27);
                           }
                        }

                        if (this.j.b != null && var25 >= this.j.b.d) {
                           var25 = this.j.b.a(var32.c);
                        }
                     }

                     var5.a(var25);
                     break;
                  case 5:
                     zyi var31 = (zyi)var14.d;
                     if (var31.b != null) {
                        zaaw var34 = new zaaw(var31.b);
                        var34.a(var9, (byte)var28, var15, var31.c, var31.d, var31.b(this.i), this.h.getWorkbook().getSettings().e);
                        var34.a(var5);
                        if (var31.a() != null) {
                           if (var31.a().b()) {
                              zbb var26 = new zbb();
                              var26.a(var31.a());
                              var26.a(var5);
                           } else {
                              zbbn var35 = new zbbn();
                              var35.a(var31.a());
                              var35.a(var5);
                           }
                        } else if (var31.b() != null) {
                           zbsh var36 = new zbsh(var31.b());
                           var36.a(var5);
                        }

                        if (var31.c == 4) {
                           zbpy var37 = new zbpy((String)var31.d);
                           var37.a(var5);
                        }
                     }
                     break;
                  case 6:
                     var20.a((Integer)var14.d);
                     var21.a(var15);
                  }

                  var30 = var28 + 1;
                  var14 = var2.d();
               } while(var14 != null);

               if (var20.a() > 0) {
                  this.a(var5, var20, var21, var9, var30);
               } else if (var21.a() > 0) {
                  this.a(var5, var21, var9, var30);
               }
            }

            zbbk var33 = new zbbk();
            var33.a(var18, var29, var30);
            if (var23.size() < 1) {
               com.aspose.cells.b.a.a.ze.a(var23, (Object)var1.b());
               long var38 = var6.i();
               var33.a(var7);
               com.aspose.cells.b.a.a.ze.a(var23, (Object)(var6.i() - var38));
               com.aspose.cells.b.a.a.ze.a(var23, (Object)0L);
            } else {
               var33.a(var7);
            }

            if (var30 > 0) {
               if (var30 > this.d) {
                  this.d = var30;
               }

               if (this.a < 0) {
                  this.a = var9;
               }

               this.b = var9;
               com.aspose.cells.b.a.a.ze.a(var23, (Object)var4.i());
            }

            var3 = var2.c();
         } while(var3 != null);

         this.a(var23, var4, var6, var1, var8);
         if (this.a < 0) {
            this.a = 0;
            this.c = 0;
         } else {
            ++this.b;
         }

      }
   }

   private void a(ArrayList var1, com.aspose.cells.b.a.d.zh var2, com.aspose.cells.b.a.d.zh var3, zqa var4, int var5) throws Exception {
      if (var1.size() > 0) {
         var1.set(1, ((Long)var1.get(1) & 4294967295L) - var3.i());
         if (var2.h() < 1L) {
            com.aspose.cells.b.a.a.ze.a(var1, 2, var1.size() - 2);
         } else {
            var1.remove(var1.size() - 1);
         }

         com.aspose.cells.b.a.d.zm var6 = var4.a();
         var3.a(var6);
         var3.a(0L);
         var2.a(var6);
         var2.a(0L);
      }

      this.e.a((int)var4.b() - var5);
      znh var7 = new znh();
      var7.a(var1);
      var7.a(var4);
      var1.clear();
   }

   private void a(zqa var1, zakl var2, zakl var3, int var4, int var5) throws Exception {
      int var6 = var2.a();
      var5 -= var6;
      if (var6 == 1) {
         var1.a((short)638);
         var1.a((short)10);
         var1.b(var4);
         var1.a((short)var5);
         var1.a((short)var3.b(0));
         var1.a(var2.b(0));
      } else {
         var1.a((short)189);
         var1.a((short)(6 + 6 * var6));
         var1.b(var4);
         var1.a((short)var5);

         for(int var7 = 0; var7 < var6; ++var7) {
            var1.a((short)var3.b(var7));
            var1.a(var2.b(var7));
            ++var5;
         }

         var1.a((short)(var5 - 1));
      }

      var2.c();
      var3.c();
   }

   private void a(zqa var1, zakl var2, int var3, int var4) throws Exception {
      int var5 = var2.a();
      var4 -= var5;
      if (var5 == 1) {
         var1.a((short)513);
         var1.a((short)6);
         var1.b(var3);
         var1.a((short)var4);
         var1.a((short)var2.b(0));
      } else {
         var1.a((short)190);
         var1.a((short)(6 + 2 * var5));
         var1.b(var3);
         var1.a((short)var4);

         for(int var6 = 0; var6 < var5; ++var6) {
            var1.a((short)var2.b(var6));
            ++var4;
         }

         var1.a((short)(var4 - 1));
      }

      var2.c();
   }
}
